package com.example.administrator.managesystem.activity.my_profile;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.activity.login.RegisterActivity;
import com.example.administrator.managesystem.base.BaseActivity;
import com.example.administrator.managesystem.utils.ConstantUtil;
import com.example.administrator.managesystem.utils.ToastUtils;
import com.example.administrator.managesystem.view.CertifyDialog;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class CertifyDataActivity extends BaseActivity {
    private TextView commit;
    private ImageView add,add_after,add_before;
    private List<LocalMedia> selectList = new ArrayList<>();
    @Override
    public void initView() {
        showfloatButton(true,true);
        commit=findViewById(R.id.commit_tv);
        add=findViewById(R.id.add_card);
        add_after=findViewById(R.id.card_after);
        add_before=findViewById(R.id.card_before);
    }

    @Override
    public void doBusiness() {

       add.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               //              // 进入相册 以下是例子：不需要的api可以不写
               PictureSelector.create(CertifyDataActivity.this)
                       .openGallery(PictureMimeType.ofImage())
                       .imageFormat(PictureMimeType.PNG)
                       .previewImage(true)// 是否可预览图片
                       .selectionMode(PictureConfig.SINGLE)
                       .isCamera(true)
                       .compress(true)
                       .glideOverride(261, 152)
                       .minimumCompressSize(100)// 小于 100kb 的图片不压缩
                       .cropCompressQuality(90)// 裁剪压缩质量 默认100
                       .selectionMedia(selectList)
                       .forResult(PictureConfig.CHOOSE_REQUEST);

           }
       });

       commit.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
//               final CertifyDialog certifyDialog=new CertifyDialog(CertifyDataActivity.this);
//               certifyDialog.setOnSureListener(new View.OnClickListener() {
//                   @Override
//                   public void onClick(View v) {
//                       certifyDialog.dismiss();
//                   }
//               });
//               certifyDialog.show();
               if(selectList.isEmpty()){
                   ToastUtils.showToast(CertifyDataActivity.this,"请上传身份证");
                   return;
               }

               ToastUtils.showToast(CertifyDataActivity.this,"添加成功！");
               ConstantUtil.IMGURL=selectList.get(0).getCompressPath();
               finish();
           }
       });
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST:
                    // 图片选择
                    selectList=PictureSelector.obtainMultipleResult(data);
                    Log.e("msg","path:"+selectList.get(0).getPath());
                    File file = new File(selectList.get(0).getCompressPath());
                    Picasso.with(CertifyDataActivity.this).load(file).into(add);
                    add_before.setVisibility(View.INVISIBLE);
                    break;
            }
        }
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_certify_data;
    }
}
